package com.zhima.feignclient;

import com.lizhi.dto.CompleteResult;
import com.lizhi.entity.LocalTask;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@FeignClient("oj-dt-service")
@RequestMapping("/oj-dt/zhima-task")
public interface LocalTaskFeignClient {
    /**
     * 发布{taskType}类型的任务，业务主键集合是businessKeys
     *
     * @param taskType
     * @param businessKeys
     * @return
     */
    @PostMapping("/publish/{taskType}")
    boolean publishTask(@PathVariable("taskType") String taskType, @RequestBody List<String> businessKeys);

    /**
     * 根据{taskType}分发任务，限制{limit}个
     *
     * @param taskType
     * @param limit
     * @return
     */
    @GetMapping("/dispatchTasks/{taskType}/{limit}")
    List<LocalTask> dispatchTasks(@PathVariable("taskType") String taskType, @PathVariable("limit") Integer limit);

    /**
     * 根据分片参数和{taskType}分发任务，限制{limit}个
     *
     * @param shardSize
     * @param shardIndex
     * @param taskType
     * @param limit
     * @return
     */
    @GetMapping("/dispatchTasks/{shardSize}/{shardIndex}/{taskType}/{limit}")
    List<LocalTask> dispatchTasksBasedOnShared(@PathVariable("shardSize") Integer shardSize, @PathVariable("shardIndex") Integer shardIndex, @PathVariable("taskType") String taskType, @PathVariable("limit") Integer limit);

    /**
     * 通知完成{taskId}的子任务
     *
     * @param taskId
     * @return
     */
    @PostMapping("/completeSubTask/{taskId}")
    boolean completeSubTaskWithSubTaskIndex(@PathVariable("taskId") Integer taskId, @RequestBody CompleteResult completeResult);

    /**
     * 开始{taskId}任务
     *
     * @param taskId
     * @param subTaskIndex
     * @return
     */
    @PostMapping("/startSubtask/{taskId}/{subTaskIndex}")
    boolean startSubTaskWithSubTaskIndex(@PathVariable("taskId") Integer taskId,
                                         @PathVariable("subTaskIndex") Integer subTaskIndex);

    /**
     * 开始{taskId}任务的子任务，默认从尚未完成的子任务开始
     *
     * @param taskId
     * @return
     */
    @PostMapping("/startSubtask/{taskId}")
    boolean startSubTaskWithoutSubTaskIndex(@PathVariable("taskId") Integer taskId);
}
